package com.ln.dm1102.demo01;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/11/2 15:14
 */
public class TestExecutors {
    public static void main(String[] args) {
        //创建单一线程池
//        ExecutorService executorService = Executors.newSingleThreadExecutor();
        //创建固定长度的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(5);
        //创建可变线程池
//        ExecutorService executorService = Executors.newCachedThreadPool();
        //创建延迟线程池
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(5);


        for (int i = 0; i < 10; i++) {
            final int a=i;
//            executorService.submit(new Runnable() {
//                @Override
//                public void run() {
//                    System.out.println(Thread.currentThread().getName()+"==="+a);
//                }
//            });


            executorService.schedule(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"===="+a);
                }
            },5, TimeUnit.SECONDS);
        }

    }
}
